package com.central.apps.service.impl;

import com.central.app.service.HandlerService;
import com.central.apps.service.ManHourStatisticsService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.collections.MapUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * 工时接口实现类
 *
 * @author 李大超
 * @date 2023/1/30
 */
@Slf4j
@Service
public class ManHourStatisticsServiceImpl implements ManHourStatisticsService {

    @Autowired
    private HandlerService handlerService;

    /**
     * 工时统计
     *
     * @param proid
     */
    @Override
    public void manHourStatistics(Integer proid) throws Exception {
        int totalHours = 0;
        // 统计项目总工时
        List<Map<String, Object>> list = handlerService.findBySql("select ifnull(sum(manhour), 0) as totalHours from gq_manhourstatistics where proid = "+ proid);

        if (CollectionUtils.isNotEmpty(list)) {
            Map<String, Object> map = list.get(0);
            totalHours = MapUtils.getInteger(map, "totalHours");

            // 更新项目总工时
            handlerService.updateBySql("update gq_proaccount set totalhours = " + totalHours + " where id = "+ proid);
        }
    }
}
